package windows.treeWindow
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import com.bit101.components.Label;
	/**
	 * вот я тут нахуеверчу кода то
	 * @author yaempechenki@gmail.com
	 */
	public class TreeItemView extends Sprite
	{
		private var _id:int;
		private var label:Label;
		private var background:Sprite;
		private var rectangle:Sprite;
		public function TreeItemView(_id:int, title:String)
		{
			this._id = _id;
			
			background = new Sprite();
			background.graphics.clear();
			background.graphics.beginFill(0xBEBEBE);
			background.graphics.drawRect(0, 0, 110, 10);
			background.graphics.endFill();
			background.alpha = 0.5;
			background.mouseEnabled = false;
			addChild(background);
			
			rectangle = new Sprite();
			rectangle.mouseEnabled = false;
			addChild(rectangle);
			
			label = new Label(this, 0, 0, title);
			label.x = 12;
			label.y = 10 / 2 - label.height / 2;
			
			selected = false;
			buttonMode = true;
			
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOut(event:MouseEvent):void 
		{
			background.alpha = 0.5;
		}
		
		private function onMouseOver(event:MouseEvent):void 
		{
			background.alpha = 1;
		}
		
		public function set selected(value:Boolean):void {
			const color:uint = value ? 0x787878: 0xCDCDCD;
			rectangle.graphics.clear();
			rectangle.graphics.beginFill(color);
			rectangle.graphics.drawRect(0, 0, 10, 10);
			rectangle.graphics.endFill();
		}
		
		public function get id():int {
			return _id;
		}
	}
}